Read me for script 

This R script is to merge FDI catch by country data (Table A) with the age and length data for both landings and discards (biological tables C, D, E and F). The format of the files required for this script must be downloaded from the data dissemination page Fisheries Dependent Information - European Commission (europa.eu). The scripts should be run using the files contained in the zipped folders named FDI Catches 2013-2022 and FDI Biological Data 2013-2022.
The R script to run is scriptToMergeTables.r which uses load_format_function.r and mergeFunction.r scripts. Define the correct working directory on line 35 (WDData) to store the tables downloaded from the dissemination page and to save the final output. On line 36 (WDScript) you have to define the correct working directory to store the 3 scripts (scriptToMergeTables.r, load_format_function.r and mergeFunction.r). By changing line 37 in scriptToMergeTables.r to either Age or Length, respectively, as result the age or length tables of the landings and discards is merged with the catch by country table. The time frame of the data sets is defined on line 38. 
Merging is made on: COUNTRY_CODE, YEAR, DOMAIN_LANDINGS, SPECIES, NEP_SUB_REGION for landings and COUNTRY_CODE, YEAR, DOMAIN_DISCARDS, SPECIES, NEP_SUB_REGION for discards. The final tables produced by the scripts is tableA_AtAge.rds if age structured data are asked or tableA_AtLength.rds if length structured data are asked. These tables and some intermediate tables are saved in the folder defined by WDData.   
When merging these tables, it should be kept in mind that domains are defined to match the sampling program designs and to ensure that the raising procedures are statistically sound. Raising procedures concern discards estimates, and landings/discards length/age structures. One domain then corresponds to one line in the biological tables (C-F) but potentially to multiple gear/mesh size/quarters in table A depending on the strata aggregation of the sampling design. 
Merging the catch table and biological tables allows you to define a length/age structure for each line of the catch table but by doing so, the sampling design is no longer followed. The main assumption is that the length/age structure, and discard ratio, are homogeneous within a domain, however this assumption may not reflect the reality of the fishery. 
Keep in mind that if a certain domain is marked as confidential then the merging cannot be completed for that domain.
For more detailed information on how the merging is done please refer to the EWG FDI 22-10 section 3.3.1. The update of the script was done during EWG 23-05 FDI Methodology meeting. 
